package com.wxx.performance;

public class TemperatureReader {
    static {
        System.loadLibrary("Kernel32");
    }

    public native int GetSystemPowerStatus(byte[] buffer);

    public float getTemperature() {
        byte[] buffer = new byte[256];
        int result = GetSystemPowerStatus(buffer);
        if (result != 0) {
            int temperature = buffer[116] & 0xFF;
            return (float) temperature / 10;
        } else {
            return -1.0f;
        }
    }

    public static void main(String[] args) {
        TemperatureReader reader = new TemperatureReader();
        float temperature = reader.getTemperature();
        if (temperature != -1.0f) {
            System.out.println("Current temperature: " + temperature + "°C");
        } else {
            System.out.println("Failed to get temperature data.");
        }
    }
}
